package com.domino.server.user;

import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import javax.servlet.http.Cookie;


public class DebugOutputUtil {

	public static String toStringArray(Cookie[] cookies) {
		if (cookies==null) {
			return "null";
		}
		StringBuilder sb = new StringBuilder();
		for(Cookie c : cookies) {
			sb.append(CookieUtil.toString(c) + "<br>\n");
		}
		return sb.toString();
	}
	
	public static String toString(Map parameterMap) {
		if (parameterMap==null) {
			return "null";
		}
		
		StringBuilder sb = new StringBuilder();
		Iterator entrySet = parameterMap.entrySet().iterator();
		sb.append("[<br>\n");
		while (entrySet.hasNext()) {
			Map.Entry entry = (Entry) entrySet.next();
			sb.append("{");
			sb.append(entry.getKey().toString());
			sb.append(",");
			sb.append(toArrayString((String[]) entry.getValue()));
			sb.append("}<br>\n");
		}
		sb.append("]");
		return sb.toString();
	}

	static private String toArrayString(String[] value) {
		StringBuilder sb = new StringBuilder();
		for (String s : value) {
			sb.append("'");
			sb.append(s);
			sb.append("' ");
		}
		return sb.toString();
	}


}
